package com.huitone.smspfm.core.config;

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.huitone.smspfm.MyTest;
import com.huitone.smspfm.logger.ExtLogger;

import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import com.alibaba.fastjson.JSONArray;
import com.bin.common.utils.FileUtils;
import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.context.utils.ContextPropertiesUtils;
import com.huitone.smspfm.context.utils.ContextUtils;
import com.huitone.smspfm.core.filter.SmsRouteFilterTask;
import com.huitone.smspfm.core.waterpipe.client.IGateLink;
import com.huitone.smspfm.core.waterpipe.client.impl.SimpleGateLink;
import com.huitone.smspfm.core.waterpipe.client.impl.SimpleGateLinkRegister;
import com.huitone.smspfm.dao.oracle.AffixRuleDao;
import com.huitone.smspfm.dao.oracle.BlackuseDao;
import com.huitone.smspfm.dao.oracle.CallTestGateDao;
import com.huitone.smspfm.dao.oracle.CallTestPhoneDao;
import com.huitone.smspfm.dao.oracle.ForbidRuleDao;
import com.huitone.smspfm.dao.oracle.GateAutoSwitchDao;
import com.huitone.smspfm.dao.oracle.GateDefDao;
import com.huitone.smspfm.dao.oracle.GateSwitchDao;
import com.huitone.smspfm.dao.oracle.InvaliduseDao;
import com.huitone.smspfm.dao.oracle.LinkSendCorpDao;
import com.huitone.smspfm.dao.oracle.LinkSendProDao;
import com.huitone.smspfm.dao.oracle.MoInsDao;
import com.huitone.smspfm.dao.oracle.PlatformSmsTemplateDao;
import com.huitone.smspfm.dao.oracle.PriAllocDao;
import com.huitone.smspfm.dao.oracle.PriRuleDefDao;
import com.huitone.smspfm.dao.oracle.ReduserListDao;
import com.huitone.smspfm.dao.oracle.RepeatRuleDao;
import com.huitone.smspfm.dao.oracle.SensitiveDao;
import com.huitone.smspfm.dao.oracle.ServiceCodeDefDao;
import com.huitone.smspfm.dao.oracle.SmSignDao;
import com.huitone.smspfm.dao.oracle.SmsCallTestDao;
import com.huitone.smspfm.dao.oracle.SvrNodeDefDao;
import com.huitone.smspfm.dao.oracle.SvrRouteRuleDao;
import com.huitone.smspfm.dao.oracle.UserRouteRuleDao;
import com.huitone.smspfm.dao.oracle.VirtualGateLinkDao;
import com.huitone.smspfm.dao.oracle.WarnRecvDao;
import com.huitone.smspfm.dao.oracle.entity.AffixRule;
import com.huitone.smspfm.dao.oracle.entity.BlackUse;
import com.huitone.smspfm.dao.oracle.entity.CallTestGate;
import com.huitone.smspfm.dao.oracle.entity.CallTestPhone;
import com.huitone.smspfm.dao.oracle.entity.ForbidRule;
import com.huitone.smspfm.dao.oracle.entity.GateAutoSwitch;
import com.huitone.smspfm.dao.oracle.entity.GateDef;
import com.huitone.smspfm.dao.oracle.entity.GateSwitch;
import com.huitone.smspfm.dao.oracle.entity.LinkSendCorp;
import com.huitone.smspfm.dao.oracle.entity.LinkSendPro;
import com.huitone.smspfm.dao.oracle.entity.MoIns;
import com.huitone.smspfm.dao.oracle.entity.PlatformSmsTemplate;
import com.huitone.smspfm.dao.oracle.entity.PriAlloc;
import com.huitone.smspfm.dao.oracle.entity.PriRuleDef;
import com.huitone.smspfm.dao.oracle.entity.ReduserList;
import com.huitone.smspfm.dao.oracle.entity.RepeatRule;
import com.huitone.smspfm.dao.oracle.entity.Sensitive;
import com.huitone.smspfm.dao.oracle.entity.SmSign;
import com.huitone.smspfm.dao.oracle.entity.SmsCallTest;
import com.huitone.smspfm.dao.oracle.entity.SvrNodeCodeRlt;
import com.huitone.smspfm.dao.oracle.entity.SvrNodeDef;
import com.huitone.smspfm.dao.oracle.entity.SvrRouteRule;
import com.huitone.smspfm.dao.oracle.entity.UserRouteRule;
import com.huitone.smspfm.dao.oracle.entity.VirtualGateLink;
import com.huitone.smspfm.dao.oracle.entity.WarnRecv;
import com.huitone.smspfm.redis.impl.HashOpts;
import com.huitone.smspfm.redis.impl.KeyOpts;
import com.huitone.smspfm.redis.impl.ListOpts;
import com.huitone.smspfm.redis.impl.ScriptOpts;
import com.huitone.smspfm.redis.impl.SetOpts;
import com.huitone.smspfm.redis.impl.StringOpts;
import com.huitone.smspfm.redis.impl.ZsetOpts;
import com.huitone.smspfm.redis.pipeline.PipelineOpts;
import com.huitone.smspfm.redis.pipeline.PipelineOpts.ABExcuteCommands;

/**   
* @Title StaticConfigs.java 
* @Package com.huitone.smspfm.core.config.impl 
* @Description 保存全局可用参数或者配置文件,方便程序使用以及重新加载 
* @author ybliang   
* @date 2017年5月17日 下午5:46:16 
* @version V1.0   
*/
public class AppStaticConfigs {
	
	public static ExtLogger logger = ExtLogger.create(AppStaticConfigs.class);
	
	public static String appName = StringUtils.uuid();
	
	public static String appCode = null;
	
	public static SimpleGateLinkRegister simpleGateLinkRegister = null;
	
	public static RedisSerializer<String> stringRedisSerializer = new StringRedisSerializer();
	
	
	public static final class Const{
		public final static String SMS_TEMPLATE_TYPE_WGQH = "1";
		public final static String SMS_TEMPLATE_TYPE_BT = "2";
	}
	
	
	/**
	 * 保存记录运行参数的hash的key
	 */
	public static String RunningParamsHashSet = null;
	
	/**
	 * 记录运行参数的hash
	 */
	public static String RunningParamsHash = null;
	/**
	 * 记录运行参数的hash
	 */
	public static byte[] RunningParamsHashB = null;
	
	// redis1
	public static KeyOpts keyOpts = null;
	public static ZsetOpts zsetOpts = null;
	public static SetOpts setOpts = null;
	public static ListOpts listOpts = null;
	public static HashOpts hashOpts = null;
	public static StringOpts stringOpts = null;
	public static PipelineOpts pipelineOpts = null;
	public static ScriptOpts scriptOpts = null;
	
	// redis2
	public static KeyOpts keyOpts2 = null;
	public static ZsetOpts zsetOpts2 = null;
	public static SetOpts setOpts2 = null;
	public static ListOpts listOpts2 = null;
	public static HashOpts hashOpts2 = null;
	public static StringOpts stringOpts2 = null;
	public static PipelineOpts pipelineOpts2 = null;
	public static ScriptOpts scriptOpts2 = null;
	
	// redis3
	public static KeyOpts keyOpts3 = null;
	public static ZsetOpts zsetOpts3 = null;
	public static SetOpts setOpts3 = null;
	public static ListOpts listOpts3 = null;
	public static HashOpts hashOpts3 = null;
	public static StringOpts stringOpts3 = null;
	public static PipelineOpts pipelineOpts3 = null;
	public static ScriptOpts scriptOpts3 = null;
	
	/**
	 * 短信处理过滤链
	 *  smspfm.illegal.user.filter=true
		# 是否打开无效用户过滤器
		smspfm.invalid.user.filter=true
		# 是否打开黑名单用户过滤器
		smspfm.black.user.filter=true
		# 是否打开敏感词过滤器
		smspfm.sensitive.world.filter=true
		# 是否打开附加短信过滤器
		smspfm.attach.msg.filter=true
		# 是否打开重复短信过滤器
		smspfm.dulplicate.filter=true
		# 是否打开禁发时间过滤器
		smspfm.forbidtime.filter=true
		# 是否打开路由转发器
		smspfm.route.filter=true
	 */
	public static boolean illegalUserFilterOn = true;
	public static boolean invalidUserFilterOn = true;
	public static boolean blackUserFilterOn = true;
	public static boolean sensiWorldFilterOn = true;
	public static boolean attachMsgFilterOn = true;
	public static boolean sendportMsgFilterOn = true; //开启扩展码过滤任务
	public static boolean dulplicateFilterOn = true;
	public static boolean forbidtimeFilterOn = true;
	public static boolean routeFilterOn = true;
	
	/**
	 * 是否开启速率统计
	 */
	public static boolean speedStatisticsOn = false;
	
	/**
	 * 记录每秒钟速度的队列(当且仅当开启速率统计时才有效)
	 */
	public static int speedSLength = 0;
	
	/**
	 * 记录每分钟速度的队列(当且仅当开启速率统计时才有效)
	 */
	public static int speedMLength = 0;
	
	/**
	 * 是否开启处理速度控制
	 */
	public static boolean speedControllerOn = false;
	
	/**
	 * 最大处理速度
	 */
	public static int maxProccSpeed = 0;
	
	/**
	 * 下发短信处理线程池大小
	 */
	public static int mtsmsExcutePoolSize = 1; //smspfm.mtsms.excute.poolsize
	/**
	 * 下发处理时每条线程每次批量取数的数目
	 */
	public static int mtsmsBatchSizePerTime = 1000;//smspfm.mtsms.batchsize.pertime
	/**
	 * 禁发队列处理线程池大小
	 */
	public static int mtfbdExcutePoolSize = 1; //smspfm.mtfbd.excute.poolsize=10
	/**
	 * 每次最多从禁发队列中取mtfbdBatchSizePerTime条记录
	 */
	public static int mtfbdBatchSizePerTime = 1000;
	/**
	 * 上行短信处理线程池大小
	 */
	public static int mosmsExcutePoolSize = 1; //smspfm.mosms.excute.poolsize=10
	
	/**
	 * 每次最多从上行短信队列中取mosmsBatchSizePerTime条记录
	 */
	public static int mosmsBatchSizePerTime = 1000;
	
	/**
	 * 是否开启定时重载配置信息
	 */
	public static boolean reloadConfigTimingOnOff = false;
	
	/**
	 * 重载配置信息的时间间隔(单位/分钟), 只有reloadConfigTimingOnOff=true该参数才生效
	 */
	public static int reloadConfigInterval = 10;
	
	/**
	 * 是否开启拔测线程 默认不开启
	 */
	public static boolean smsCallTestOnOff = false;
	
	/**
	 * 业务端定义列表
	 */
	public static List<SvrNodeDef> configSvrNodeDefList = null;
	
	
	/**
	 * 短信类型
	 */
	public static Map<String,Map<String,String>> svrNodeCodeRlt = null;
	
	
	/**
	 * 黑名单用户集合[srvNode:serviceCode:user,srvNode:serviceCode:user, ...]
	 * 
	 */
	public static String configBlackListZSet = null;
	public static byte[] configBlackListZSetB = null;
	
	/**
	 * 无效用户集合[user,user, ...]
	 */
	public static Set<String> configInvalidUserSet = new HashSet<String>();
	
	/**
	 * 附加短信集合[srvNode:serviceCode:affixSm:moSm:timeLen:affixRuleId, srvNode:serviceCode:affixSm:timeLen:affixRuleId, ...]
	 */
	//public static String configAffixZSet = null;
	public static Map<String, Set<String>> configAffixMap = new HashMap<>(); 
	
	/**
	 * 敏感词[senName]
	 */
	//public static String configSensitiveZSet = null;
	public static Set<String> configSensitiveSet = new HashSet<>();
	
	
	/**
	 * 重复过滤规则[srvNode:serviceCode:smSeqFlag:userFlag:serviceCodeFlag:smFlag:timeLen]
	 */
	//public static String configRepeatZSet = null;
	public static Map<String,Set<String>> configRepeatMap = new HashMap<>();
	
	/**
	 * 禁发时段[srvNode:serviceCode:startTime:endTime:forbidruleId]
	 */
	//public static String configForbidTimeZSet = null;
	public static Map<String,Set<String>> configForbidTimeMap = new HashMap<>();
	
	/**
	 * 用于上行端口匹配客户端号[sendport:smpattern:srvNode]
	 */
	//public static String configMoInsSendportZSet = null;
	public static List<MoIns> configMoInsList = null;
	
	/**
	 * [SrvNode:ServiceCode:PriLevel:ruleId:recId]
	 */
	//public static String configSnodeScodePLvZSet = null;
	public static Map<String, Integer> configSnodeScodePLvMap = new HashMap<>();
	
	/**
	 * 优先级定义表中优先级最小的项Level
	 */
	//public static String configMinPLvString = null;
	public static Integer configMinPLvInteger = null;
	public static Set<Integer> configAllPLv = new HashSet<>();
	
	//public static String configAllPLvZSet = null;
	//public static byte[] configAllPLvZSetB = null;
	
	/**
	 * 签名[SrvNode:ServiceCode:SignContent]
	 */
	//public static String configSnodeScodeSignZSet = null;
	public static Map<String, String> configSnodeScodeSignMap = new HashMap<>();
	
	/**
	 * serviceCode对应的通道ID[serviceCode:通道ID]
	 */
	//public static String configScodeGtLinkIdZSet = null;
	public static Map<String, Set<String>> configScodeGtLinkIdMap = new HashMap<>();
	/**
	 * 业务路由表中所有可用的网关通道IDs
	 */
	public static Set<String> configAllGtLinkIdsSet = new HashSet<>();
	
	/**
	 * [可发送省份:通道ID]
	 */
	//public static String configProvGtLinkIdZset = null;
	public static Map<String, Set<String>> configProvGtLinkIdMap = new HashMap<>();
	
	/**
	 * [可发送运营商:通道ID]
	 */
	//public static String configCorpGtLinkIdZset = null;
	public static Map<String, Set<String>> configCorpGtLinkIdMap = new HashMap<>();
	
	/**
	 * 号段路由[号段:省份:运营商:recId]
	 */
	//public static String configUserRouteZSet = null;
	public static Map<String, String[]> configUserRouteMap = new HashMap<>();
	
	
	
	/**
	 *  通道虚通道配置表[通道ID:[虚通道ID]]
	 */
	public static Map<String,Set<String>> virtualGateLinkIdMap = new HashMap<String, Set<String>>();
	
	/**
	 * 网关网络切换配置表  
	 */
	public static Map<String,String>  gateSwitchMap = new HashMap<String, String>(); 
	
	/**
	 *  网关自动切换网络全局开关(默认开）
	 */
	public static Boolean gateAutoSwitchFlag = true;
	
	/**
	 *  平台短信内容模板
	 */
	public static Map<String,PlatformSmsTemplate> smsTemplateMap = new HashMap<String, PlatformSmsTemplate>();
	
	/**
	 ** 警告短信用户表
	 */
	public static List<WarnRecv> warnRecvList = new ArrayList<WarnRecv>();
	
	/**
	 * 系统短信发送配置
	 */
	public static String systemSmsSendSendPort = null;
	public static String systemSmsSendUser = null;
	public static String systemSmsSendSvrNode = null;
	public static String systemSmsSendPwd = null;
	public static String systemSmsSendServiceCode = null;
	public static String systemSmsSendCode = null;
	public static String systemSmsSendIp = null;
	public static String systemSmsSendPort = null;
	
	
	/**
	 * 红名单用户
	 */
	public static Map<String,ReduserList> reduserListMap = new HashMap<String, ReduserList>();
	
	/**
	 * 拔测短信配置表 [0..59][Set]
	 */
//	public static Map<Integer,Set<SmsCallTest>> smsCallTestMap = new HashMap<Integer, Set<SmsCallTest>>();
	
	/**
	 * [mobileCorp:[gateLinkIds]]
	 */
	public static Map<String,Set<String>> gateMobileCorpSet = new HashMap<String, Set<String>>();
	
	/**
	 * [phone:mobileCorp]
	 */
	public static Map<String,String> phoneMobileCorpMap = new HashMap<String, String>();
	/**
	 * 拔测短信配置[模板,手机，通道]表
	 */
	//TODO
	public static Map<Integer,Set<String>> smsCallTestSentMap = new HashMap<Integer, Set<String>>();
	public static SmsCallTest smsCallTest = null;
	public static Set<String> smsCallTestPhoneSet = new HashSet<String>();
	public static Set<String> smsCallTestGateSet = new HashSet<String>();
	
	public static String iSMCacheList = null;
	public static byte[] iSMCacheListB = null;
	public static String pSMCacheHash = null;
	
	public static String iSMTempSet = null;
	public static byte[] iSMTempSetB = null;
	
	public static String iSMNotifyList = null;
	public static byte[] iSMNotifyListB = null;
	
	public static String iSMNotifyEndList = null;
	public static byte[] iSMNotifyEndListB = null;
	
	public static String iSMForbidList = null;
	
	public static String iSMForbidZSet = null;
	public static byte[] iSMForbidZSetB = null;
	
	/**
	 * 重复的短信列表，该列表是从左边压入最新数据
	 */
	public static String iSMRepList = null;
	public static byte[] iSMRepListB = null;
	
	/**
	 * 去重集合
	 */
    public static String iSMRepZSet = null;
    public static byte[] iSMRepZSetB = null;
	
	public static String iSMAffixZSet = null;
	public static byte[] iSMAffixZSetB = null;
	
	public static String pSMAffix = null;
	
	public static String iSMMoGateList = null;
	
	public static String iSMMoDealList = null;
	public static byte[] iSMMoDealListB = null;
	
	public static String iSMMoEndList = null;
	public static byte[] iSMMoEndListB = null;
	
	public static String iSMInvalidList = null;
	
	public static String iSMBlackList = null;
	
	public static String iSMSensList = null;
	
	/**
	 * 被预处理程序拦截的短信队列
	 */
	public static String iSMInterceptList = null;
	/**
	 * 被预处理程序拦截的短信队列
	 */
	public static byte[] iSMInterceptListB = null;
	
	/**
	 * 路由失败的短信队列
	 */
	public static String iSMRouteFailedList = null;
	
	/**
	 * 路由失败的短信队列
	 */
	public static byte[] iSMRouteFailedListB = null;
	
	/**
	 * 集合,用于存放优先级队列名
	 */
	public static String iSMPriListNamesSet = null;
	/**
	 * 集合,用于存放优先级队列名
	 */
	public static byte[] iSMPriListNamesSetB = null;
	
	/**
	 * 用于存放拔测短信的队列名
	 */
	public static String isMCallTest = null;
	public static byte[] isMCallTestB = null;
	public static String isMcallTestSend = null;
	public static byte[] isMcallTestSendB = null;
	
	// lua 脚本开始
	public static String luaGetSmsCache = null;
	public static String luaBlackChecker = null;
	public static String luaRepeatChecker = null;
	public static String luaGetForbid = null;
	public static String luaGetMoSms = null;
	public static String luaMoSmsBlackChecker = null;
	public static String luaGetRebuildPri = null;
	public static String luaGetPriListLength = null;
	public static String luaGetPriListName = null;
	public static String luaTransferPriList = null;
	
	public static String luaGetCallTestList = null;
	public static String luaGetCallTestListKeys = null;
	// lua 脚本结束
	
	static {
		ContextUtils.getInstance();
	}
	
	/**
	 * 初始化静态参数
	 */
	public static void init() {
		initRedisDataStructure();
		initRedisOpts();
		initOracleConfig2();
		initGateLinkRegister();
		initLuaScript();
	}
	
	public static void reload() {
		init();
	}
	
	private static void initLuaScript() {
		
		
		boolean isWindows = System.getProperty("os.name").indexOf("Window") >= 0;
		
		// 获取SmsCache列表的短信
		StringBuffer bufferGetSmsCache = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/getsmscache.lua").getPath().substring(1).replace("/", "\\\\");
				bufferGetSmsCache = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {	
			bufferGetSmsCache = FileUtils.read(SmsRouteFilterTask.class.getClassLoader().getResourceAsStream("lua/getsmscache.lua"));
		}		
		if (bufferGetSmsCache != null) {
			luaGetSmsCache = bufferGetSmsCache.toString();
		}
		
		// 黑名单判断lua
		StringBuffer stringBuffer1 = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/blackchecker.lua").getPath().substring(1).replace("/", "\\\\");
				stringBuffer1 = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			stringBuffer1 = FileUtils.read(SmsRouteFilterTask.class.getClassLoader().getResourceAsStream("lua/blackchecker.lua"));
		}
		if (stringBuffer1 != null) {
			luaBlackChecker = stringBuffer1.toString();
		}
		
		// 重复检查 lua
		StringBuffer stringBuffer5 = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/repeatchecker.lua").getPath().substring(1).replace("/", "\\\\");
				stringBuffer5 = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			stringBuffer5 = FileUtils.read(SmsRouteFilterTask.class.getClassLoader().getResourceAsStream("lua/repeatchecker.lua"));
		}
		if (stringBuffer5 != null) {
			luaRepeatChecker = stringBuffer5.toString();
		}
		
		// 从禁发集合中读取已过禁发时间的短信luaGetForbid
		StringBuffer bufferGetForbid = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/getforbid.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferGetForbid = FileUtils.read(new FileInputStream(path));
				// StringBuffer bufferGetForbid =
				// FileUtils.read(SmsRouteFilterTask.class.getClassLoader().getResourceAsStream("lua/getforbid.lua"));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {

			bufferGetForbid = FileUtils.read(SmsRouteFilterTask.class
					.getClassLoader().getResourceAsStream("lua/getforbid.lua"));
		}
		if (bufferGetForbid != null) {
			luaGetForbid = bufferGetForbid.toString();
		}
		
		
		// 从上行短信队列中读取 luaGetMoSms
		StringBuffer bufferGetMoSms = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/getmosms.lua").getPath().substring(1).replace("/", "\\\\");
				bufferGetMoSms = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetMoSms = FileUtils.read(SmsRouteFilterTask.class.getClassLoader().getResourceAsStream("lua/getmosms.lua"));
		}
		if (bufferGetMoSms != null) {
			luaGetMoSms = bufferGetMoSms.toString();
		}
		
		// 从上行短信队列中读取 luaGetMoSms
		StringBuffer bufferMoSmsBlackChecker = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/moaddblackchecker.lua").getPath().substring(1).replace("/", "\\\\");
				bufferMoSmsBlackChecker = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
		
			bufferMoSmsBlackChecker = FileUtils.read(SmsRouteFilterTask.class.getClassLoader().getResourceAsStream("lua/moaddblackchecker.lua"));
		}
		if (bufferMoSmsBlackChecker != null) {
			luaMoSmsBlackChecker = bufferMoSmsBlackChecker.toString();
		}
		
		// 从上行短信队列中读取 luaGetMoSms
		StringBuffer bufferGetRebuildPri = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/getrebuildPri.lua").getPath().substring(1).replace("/", "\\\\");
				bufferGetRebuildPri = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
		
			bufferGetRebuildPri = FileUtils.read(SmsRouteFilterTask.class.getClassLoader().getResourceAsStream("lua/getrebuildPri.lua"));
		}
		if (bufferGetRebuildPri != null) {
			luaGetRebuildPri = bufferGetRebuildPri.toString();
		}
		
		// luaGetPriListLength
		StringBuffer bufferGetPriListLength = null;
		if(isWindows){
			try {
				String path = AppStaticConfigs.class.getClassLoader().getResource("lua/getprilistlength.lua").getPath().substring(1).replace("/", "\\\\");
				bufferGetPriListLength = FileUtils.read(new FileInputStream(path));
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetPriListLength = FileUtils.read(SmsRouteFilterTask.class.getClassLoader().getResourceAsStream("lua/getprilistlength.lua"));
		}
		if (bufferGetPriListLength != null) {
			luaGetPriListLength = bufferGetPriListLength.toString();
		}
		
		// luaGetFriListName
		StringBuffer bufferGetPriListName = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/getPriListName.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferGetPriListName = FileUtils
						.read(new FileInputStream(path));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetPriListName = FileUtils.read(SmsRouteFilterTask.class
					.getClassLoader().getResourceAsStream(
							"lua/getPriListName.lua"));
		}
		if (bufferGetPriListName != null) {
			luaGetPriListName = bufferGetPriListName.toString();
		}
		
		// luaTransferPriList
		StringBuffer bufferTransferPriList = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/transferPriList.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferTransferPriList = FileUtils
						.read(new FileInputStream(path));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferTransferPriList = FileUtils.read(SmsRouteFilterTask.class
					.getClassLoader().getResourceAsStream(
							"lua/transferPriList.lua"));
		}
		if (bufferTransferPriList != null) {
			luaTransferPriList= bufferTransferPriList.toString();
		}
		
		// luaGetCallTestList
		StringBuffer bufferGetCallList = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/getSMCallList.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferGetCallList = FileUtils
						.read(new FileInputStream(path));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetCallList = FileUtils.read(SmsRouteFilterTask.class
					.getClassLoader().getResourceAsStream(
							"lua/getSMCallList.lua"));
		}
		if (bufferGetCallList != null) {
			luaGetCallTestList = bufferGetCallList.toString();
		}
		
		// luaGetCallTestListKeys
		StringBuffer bufferGetCallListKeys = null;
		if (isWindows) {
			try {
				String path = AppStaticConfigs.class.getClassLoader()
						.getResource("lua/getSMCallListKeys.lua").getPath()
						.substring(1).replace("/", "\\\\");
				bufferGetCallListKeys = FileUtils.read(new FileInputStream(path));

			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			bufferGetCallListKeys = FileUtils.read(SmsRouteFilterTask.class
					.getClassLoader().getResourceAsStream(
							"lua/getSMCallListKeys.lua"));
		}
		if (bufferGetCallListKeys != null) {
			luaGetCallTestListKeys = bufferGetCallListKeys.toString();
		}
		
	}
	
	/**
	 * 初始化Redis的数据结构名
	 */
	private static void initRedisDataStructure() {
		
		appName = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.module.name")); 
		appCode = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.module.code"));
		
		RunningParamsHashSet = ContextPropertiesUtils.getProperty("RunningParamsHashSet");
		RunningParamsHash = ContextPropertiesUtils.getProperty("RunningParamsHashPrefix") + ":" + appName + ":" + appCode;
		RunningParamsHashB = stringRedisSerializer.serialize(RunningParamsHash);
		
		mtsmsExcutePoolSize = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.mtsms.excute.poolsize"),1);
		mtsmsBatchSizePerTime = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.mtsms.batchsize.pertime"),1000);
		mtfbdExcutePoolSize = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.mtfbd.excute.poolsize"),1);
		mtfbdBatchSizePerTime = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.mtfbd.batchsize.pertime"),1000);
		mosmsExcutePoolSize = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.mosms.excute.poolsize"),1);
		mosmsBatchSizePerTime = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.mosms.batchsize.pertime"),1000);
		
		illegalUserFilterOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.illegal.user.filter")) ? true : false;
		invalidUserFilterOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.invalid.user.filter")) ? true : false;
		blackUserFilterOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.black.user.filter")) ? true : false;
		sensiWorldFilterOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.sensitive.world.filter")) ? true : false;
		attachMsgFilterOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.attach.msg.filter")) ? true : false;
		sendportMsgFilterOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.sendport.msg.filter")) ? true : false;
		
		dulplicateFilterOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.dulplicate.filter")) ? true : false;
		forbidtimeFilterOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.forbidtime.filter")) ? true : false;
		routeFilterOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.route.filter")) ? true : false;
		speedStatisticsOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.speed.statistics"));
		speedControllerOn = "on".equals(ContextPropertiesUtils.getProperty("smspfm.speed.controller"));
		
		maxProccSpeed = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.max.procc.speed"), mtsmsBatchSizePerTime);
		if (maxProccSpeed < mtsmsBatchSizePerTime) {
			maxProccSpeed = mtsmsBatchSizePerTime;
		}
		speedSLength = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.speed.s.length"), 3600);
		speedMLength = StringUtils.strToInt(ContextPropertiesUtils.getProperty("smspfm.speed.m.length"), 1440);
		
		
		configBlackListZSet = ContextPropertiesUtils.getProperty("zset.blacklist.rule");
		configBlackListZSetB = stringRedisSerializer.serialize(configBlackListZSet);
		//configInvalidUserZSet = ContextPropertiesUtils.getProperty("zset.invalid.user.rule");
		//configInvalidUserZSetB = stringRedisSerializer.serialize(configInvalidUserZSet);
		//configAffixZSet = ContextPropertiesUtils.getProperty("zset.affix.rule");
		//configSensitiveZSet = ContextPropertiesUtils.getProperty("zset.sensitive.rule");
		//configRepeatZSet = ContextPropertiesUtils.getProperty("zset.repeat.rule");
		//configForbidTimeZSet = ContextPropertiesUtils.getProperty("zset.forbid.time.rule");
		//configMoInsSendportZSet = ContextPropertiesUtils.getProperty("zset.moins.sendport.rule");
		//configSnodeScodeSignZSet = ContextPropertiesUtils.getProperty("zset.snode.scode.sign.rule");
		//configSnodeScodePLvZSet = ContextPropertiesUtils.getProperty("zset.pri.alloc.level");
		//configMinPLvString = ContextPropertiesUtils.getProperty("string.min.pri.alloc.level");
		//configAllPLvZSet = ContextPropertiesUtils.getProperty("zset.all.pri.level");
		//configAllPLvZSetB = stringRedisSerializer.serialize(configAllPLvZSet);
		//configScodeGtLinkIdZSet = ContextPropertiesUtils.getProperty("zset.scode.gtlinkid");
		//configProvGtLinkIdZset = ContextPropertiesUtils.getProperty("zset.prov.gtlinkid");
		//configCorpGtLinkIdZset = ContextPropertiesUtils.getProperty("zset.corp.gtlinkid");
		//configUserRouteZSet = ContextPropertiesUtils.getProperty("zset.user.route.rule");
		
		iSMCacheList = ContextPropertiesUtils.getProperty("SMCache");
		pSMCacheHash = ContextPropertiesUtils.getProperty("SMCacheHashPrefix");
		iSMTempSet = ContextPropertiesUtils.getProperty("SMTempSet");
		iSMNotifyList = ContextPropertiesUtils.getProperty("SMNotifyList");
		iSMNotifyEndList = ContextPropertiesUtils.getProperty("SMNotifyEndList"); 
		iSMForbidList = ContextPropertiesUtils.getProperty("SMForbidList");
		iSMForbidZSet = ContextPropertiesUtils.getProperty("SMForbidZSet");
		iSMRepList = ContextPropertiesUtils.getProperty("SMRepList"); 
		iSMRepZSet = ContextPropertiesUtils.getProperty("SMRepZSet"); 
		iSMAffixZSet = ContextPropertiesUtils.getProperty("SMAffixZSet");
		pSMAffix = ContextPropertiesUtils.getProperty("SMAffix"); 
		iSMMoGateList = ContextPropertiesUtils.getProperty("SMMoGateList");
		iSMMoDealList = ContextPropertiesUtils.getProperty("SMMoDealList");
		iSMMoEndList = ContextPropertiesUtils.getProperty("SMMoEndList");
		iSMInvalidList = ContextPropertiesUtils.getProperty("SMInvalidList");
		iSMBlackList = ContextPropertiesUtils.getProperty("SMBlackList");
		iSMSensList = ContextPropertiesUtils.getProperty("SMSensList");
		iSMInterceptList = ContextPropertiesUtils.getProperty("SMInterceptList");
		iSMInterceptListB = stringRedisSerializer.serialize(iSMInterceptList);
		iSMRouteFailedList = ContextPropertiesUtils.getProperty("SMRouteFailedList");
		iSMRouteFailedListB = stringRedisSerializer.serialize(iSMRouteFailedList);
		
		iSMTempSetB = stringRedisSerializer.serialize(iSMTempSet);
		iSMNotifyListB = stringRedisSerializer.serialize(iSMNotifyList);
		iSMNotifyEndListB = stringRedisSerializer.serialize(iSMNotifyEndList);
		iSMAffixZSetB = stringRedisSerializer.serialize(iSMAffixZSet); 
		iSMRepListB = stringRedisSerializer.serialize(iSMRepList);
		iSMRepZSetB = stringRedisSerializer.serialize(iSMRepZSet);
		iSMForbidZSetB = stringRedisSerializer.serialize(iSMForbidZSet); 
		iSMCacheListB = stringRedisSerializer.serialize(iSMCacheList);  
		iSMMoEndListB = stringRedisSerializer.serialize(iSMMoEndList); 
		iSMMoDealListB = stringRedisSerializer.serialize(iSMMoDealList);
		
		iSMPriListNamesSet = ContextPropertiesUtils.getProperty("set.pri.list.names");
		iSMPriListNamesSetB = stringRedisSerializer.serialize(iSMPriListNamesSet);
		
		isMCallTest = ContextPropertiesUtils.getProperty("call.test.list.names");
		isMCallTestB = stringRedisSerializer.serialize(isMCallTest);
		isMcallTestSend = ContextPropertiesUtils.getProperty("call.test.list.sends.names");
		isMcallTestSendB = stringRedisSerializer.serialize(isMcallTestSend);
		
		reloadConfigTimingOnOff = StringUtils.equals("on", StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.reload.config.timing")));
		reloadConfigInterval = StringUtils.toInteger(StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.reload.config.interval")), 10, true);
		
		systemSmsSendSendPort = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.system.sms.sendPort"));
		systemSmsSendUser = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.system.sms.loginUser"));
		systemSmsSendSvrNode = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.system.sms.svrNode"));
		systemSmsSendPwd = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.system.sms.loginPwd"));
		systemSmsSendServiceCode = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.system.sms.serviceCode"));
		systemSmsSendCode = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.system.sms.code"));
		systemSmsSendIp = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.system.sms.ip"));
		systemSmsSendPort = StringUtils.trim(ContextPropertiesUtils.getProperty("smspfm.system.sms.port"));
		//TODO
		
		smsCallTestOnOff = "on".equals(ContextPropertiesUtils.getProperty("smspfm.system.task.calltest")) ? true : false;
		
	}
	
	/**
	 * 初始化redis操作类
	 */
	private static void initRedisOpts() {
		
		initRedisOpts1();
		
		initRedisOpts2();
		
		initRedisOpts3();
	}

	public static void initRedisOpts3() {
		keyOpts3 = (KeyOpts) ContextUtils.getBean2("keyOpts3");
		zsetOpts3 = (ZsetOpts) ContextUtils.getBean2("zsetOpts3"); 
		setOpts3 = (SetOpts) ContextUtils.getBean2("setOpts3");
		listOpts3 = (ListOpts) ContextUtils.getBean2("listOpts3");
		hashOpts3 = (HashOpts) ContextUtils.getBean2("hashOpts3");
		stringOpts3 = (StringOpts) ContextUtils.getBean2("stringOpts3");
		pipelineOpts3 = (PipelineOpts) ContextUtils.getBean2("pipelineOpts3");
		scriptOpts3 = (ScriptOpts) ContextUtils.getBean2("scriptOpts3");
	}

	public static void initRedisOpts2() {
		keyOpts2 = (KeyOpts) ContextUtils.getBean2("keyOpts2");
		zsetOpts2 = (ZsetOpts) ContextUtils.getBean2("zsetOpts2"); 
		setOpts2 = (SetOpts) ContextUtils.getBean2("setOpts2");
		listOpts2 = (ListOpts) ContextUtils.getBean2("listOpts2");
		hashOpts2 = (HashOpts) ContextUtils.getBean2("hashOpts2");
		stringOpts2 = (StringOpts) ContextUtils.getBean2("stringOpts2");
		pipelineOpts2 = (PipelineOpts) ContextUtils.getBean2("pipelineOpts2");
		scriptOpts2 = (ScriptOpts) ContextUtils.getBean2("scriptOpts2");
	}

	public static void initRedisOpts1() {
		keyOpts = (KeyOpts) ContextUtils.getBean2("keyOpts");
		zsetOpts = (ZsetOpts) ContextUtils.getBean2("zsetOpts"); 
		setOpts = (SetOpts) ContextUtils.getBean2("setOpts");
		listOpts = (ListOpts) ContextUtils.getBean2("listOpts");
		hashOpts = (HashOpts) ContextUtils.getBean2("hashOpts");
		stringOpts = (StringOpts) ContextUtils.getBean2("stringOpts");
		pipelineOpts = (PipelineOpts) ContextUtils.getBean2("pipelineOpts");
		scriptOpts = (ScriptOpts) ContextUtils.getBean2("scriptOpts");
	}
	
	/**
	 * 登记网关通道
	 */
	private static void initGateLinkRegister() {
		simpleGateLinkRegister = ContextUtils.getBean2(SimpleGateLinkRegister.class);
		Map<String, IGateLink> gateLinksTmp = new HashMap<>();
		Map<String,Set<String>> gateMobileCorpSetTmp = new HashMap<String, Set<String>>();
		GateDefDao gateDefDao = ContextUtils.getBean2(GateDefDao.class);
		List<GateDef> allObj = gateDefDao.getAllObj();
		List<GateDef> defs = allObj != null ? (ArrayList<GateDef>) allObj : new ArrayList<>(); 
		for (GateDef def:defs) { // 登记GateLink
			if (def == null) continue;
			logger.debug(def.toString());
			gateLinksTmp.put(def.getGateLinkId(), new SimpleGateLink(def));
			String gateId = def.getGateLinkId();
			String mobileCorp = def.getMobileCorp();
			Set<String> set = null;
			if(gateMobileCorpSetTmp.containsKey(mobileCorp)){ 
				set = gateMobileCorpSetTmp.get(mobileCorp);
			} else {
				set = new HashSet<String>();
				gateMobileCorpSetTmp.put(mobileCorp, set);
			}
			set.add(gateId);
		}
		gateMobileCorpSet = gateMobileCorpSetTmp;
		//TODO  测试
		logger.info("输出通道定义表大小： "+gateMobileCorpSet.size());
		for(String key : gateMobileCorpSet.keySet()){
			StringBuffer sb = new StringBuffer();
			sb.append(" 运营商ID: "+key+" 通道ID: [ ");
			Set<String> tmpSet = gateMobileCorpSet.get(key);
			for(String tmpKey : tmpSet){
				sb.append(tmpKey+",");
			}
			sb.append(" ] ");
			logger.info(sb.toString());
		}
		simpleGateLinkRegister.setGateLinks(gateLinksTmp);
		
		/**
		 * 登记网关虚通道
		 */
		
		Map<String, Set<String>> virtualGateLinkIdMapTmp = new HashMap<>();
		List<VirtualGateLink> srs = ContextUtils.getBean2(VirtualGateLinkDao.class).getAllObj();
		for (VirtualGateLink sr:srs) {
			String gateLinkId = StringUtils.toString(sr.getGateLinkId());
			String virtualGateLinkId = StringUtils.toString(sr.getVirtualGateLinkId());
						
			Set<String> set = virtualGateLinkIdMapTmp.get(gateLinkId);
			if (set == null) {
				set = new HashSet<>();
				set.add(virtualGateLinkId);
				virtualGateLinkIdMapTmp.put(gateLinkId, set);
			} else {
				set.add(virtualGateLinkId);
			}
		}
		
		virtualGateLinkIdMap = virtualGateLinkIdMapTmp;
			
	}
	
	private static void initOracleConfig2() {
		
		long score = System.currentTimeMillis();
		
		StringBuffer buffer = new StringBuffer();
		
		List<SvrNodeDef> snds = ContextUtils.getBean2(SvrNodeDefDao.class).getAllObj();
		configSvrNodeDefList = snds != null ? snds : new ArrayList<>();
		
		// 加载无效用户
		Set<String> configInvalidUserSetTmp = new HashSet<String>();
		List<String> invalidUsers = ContextUtils.getBean2(InvaliduseDao.class).getInvalidUsers();
		for (String user:invalidUsers) {
			configInvalidUserSetTmp.add(user);
		}
		configInvalidUserSet = configInvalidUserSetTmp;
		
		
		//加载短信类型数据
		Map<String,Map<String,String>> srvNSCodeMapTmp = new HashMap<>();
//		List<SvrNodeCodeRlt> svrNodeCodeRltList = ContextUtils.getBean2(ServiceCodeDef.class).getAll();
		List<Map<String,Object>> svrNodeCodeRltList  = ContextUtils.getBean2(ServiceCodeDefDao.class).getAll();
		for (Map<String, Object> mape : svrNodeCodeRltList) {
			
			String svrNode = StringUtils.toString(mape.get("SVR_NODE"));
			String serviceCode = StringUtils.toString(mape.get("SERVICE_CODE"));
			String acceptMO = StringUtils.toString(mape.get("ACCEPT_MO"));//短信类型是否接受上行短信
			
			Map<String,String> map = srvNSCodeMapTmp.get(svrNode);
			if (map == null) {
				map = new HashMap<String,String>();
				map.put(serviceCode, acceptMO);
				srvNSCodeMapTmp.put(svrNode, map);
			} else {
				map.put(serviceCode, acceptMO);//同一个业务端系统 可以有又多个 短信类型
			}
			
		}
		svrNodeCodeRlt = srvNSCodeMapTmp;
		
//		for (SvrNodeCodeRlt svrNodeCodeRlt:svrNodeCodeRltList) {
//			
//			String svrNode = StringUtils.toString(svrNodeCodeRlt.getSvrNode());
//			String serviceCode = StringUtils.toString(svrNodeCodeRlt.getServiceCode());
//			String acceptMO = StringUtils.toString(svrNodeCodeRlt.getAccept_MO());//短信类型是否接受上行短信
//			
//			Map<String,String> map = srvNSCodeMapTmp.get(svrNode);
//			if (map == null) {
//				map = new HashMap<String,String>();
//				map.put(serviceCode, acceptMO);
//				srvNSCodeMapTmp.put(svrNode, map);
//			} else {
//				map.put(serviceCode, acceptMO);//同一个业务端系统 可以有又多个 短信类型
//			}
////			System.out.println(svrNode+"  :   "+serviceCode);
//		}
//		svrNodeCodeRlt = srvNSCodeMapTmp;
		/**
		 * 短信类型
		 */
//		public static Map<String,Map<String,String>> svrNodeCodeRlt = null;
		
		
		
		// 加载黑名单用户
		List<BlackUse> busers = ContextUtils.getBean2(BlackuseDao.class).getAllObj();
		AppStaticConfigs.pipelineOpts2.save(new ABExcuteCommands() {

			@Override
			public void excute(RedisConnection connection) {
				for (BlackUse buser:busers) {
					buffer.setLength(0);
					buffer.append(StringUtils.toString(buser.getSvrNode()));
					buffer.append(":");
					buffer.append(StringUtils.toString(buser.getServiceCode()));
					buffer.append(":");
					buffer.append(StringUtils.phNumRem86(StringUtils.toString(buser.getBlackUser())));
					connection.zAdd(configBlackListZSetB, score, stringRedisSerializer.serialize(buffer.toString()));
				}
			}
		});
		// 删除blackListSet集合中score小于当前score的元素
		zsetOpts2.removeByScore(configBlackListZSet, 0, score - 1);
		
		// 加载附加规则配置
		Map<String, Set<String>> configAffixMapTmp = new HashMap<>(); 
		List<AffixRule> affixRs = ContextUtils.getBean2(AffixRuleDao.class).getAllObj();
		for (AffixRule affix:affixRs) {
			
			String svrNode = StringUtils.toString(affix.getSvrNode());
			String serviceCode = StringUtils.toString(affix.getServiceCode());
			String affixSm = affix.getAffixSm();
			String moSm = affix.getMoSm();
			Integer timeLen = affix.getTimeLen();
			
			String key = svrNode + ":" + serviceCode;
			Set<String> set = configAffixMapTmp.get(key);
			if (set == null) {
				set = new HashSet<>();
				set.add(affixSm + ":" + moSm + ":" + timeLen);
				configAffixMapTmp.put(key, set);
			} else {
				set.add(affixSm + ":" + moSm + ":" + timeLen);
			}
		}
		configAffixMap = configAffixMapTmp;
		// 删除affixSet集合中score小于当前score的元素
		//zsetOpts.removeByScore(configAffixZSet, 0, score - 1);
		
		// 加载已配置敏感词
		Set<String> configSensitiveSetTmp = new HashSet<>();
		List<Sensitive> sens = ContextUtils.getBean2(SensitiveDao.class).getAllObj();
		for (Sensitive sen:sens) {
			
			String senName = StringUtils.toString(sen.getSenName());
			
			configSensitiveSetTmp.add(senName);
		}
		configSensitiveSet = configSensitiveSetTmp;
		
		// 加载重复过滤规则
		Map<String,Set<String>> configRepeatMapTmp = new HashMap<>();
		List<RepeatRule> repeats = ContextUtils.getBean2(RepeatRuleDao.class).getAllObj();
		for (RepeatRule repeat:repeats) {
			buffer.setLength(0);
			
			String svrNode = StringUtils.toString(repeat.getSvrNode());
			String serviceCode = StringUtils.toString(repeat.getServiceCode());
			String smSeq = repeat.getSmSeq();
			String userFlag = repeat.getUserFlag();
			String serviceCodeFlag = repeat.getServiceCodeFlag();
			String smFlag = repeat.getSmFlag();
			Integer timeLen = repeat.getTimeLen();
			String repeatRuleId = repeat.getRepeatRuleId();
			
			buffer.append(svrNode);
			buffer.append(":");
			buffer.append(serviceCode);
			buffer.append(":");
			buffer.append(smSeq);
			buffer.append(":");
			buffer.append(userFlag);
			buffer.append(":");
			buffer.append(serviceCodeFlag);
			buffer.append(":");
			buffer.append(smFlag);
			buffer.append(":");
			buffer.append(timeLen);
			buffer.append(":");
			buffer.append(repeatRuleId);
			
			String key = svrNode + ":" + serviceCode;
			Set<String> set = configRepeatMapTmp.get(key);
			if (set == null) {
				set = new HashSet<>();
				set.add(buffer.toString());
				configRepeatMapTmp.put(key, set);
			} else {
				set.add(buffer.toString());
			}
		}
		configRepeatMap = configRepeatMapTmp;
		
		// 加载禁发时段过滤规则
		Map<String,Set<String>> configForbidTimeMapTmp = new HashMap<>();
		List<ForbidRule> forbids = ContextUtils.getBean2(ForbidRuleDao.class).getAllObj();
		for (ForbidRule forbid:forbids) {
			buffer.setLength(0);
			
			String svrNode = StringUtils.toString(forbid.getSvrNode());
			String serviceCode = StringUtils.toString(forbid.getServiceCode());
			
			buffer.append(svrNode);
			buffer.append(":");
			buffer.append(serviceCode);
			buffer.append(":");
			buffer.append(forbid.getStartTime());
			buffer.append(":");
			buffer.append(forbid.getEndTime());
			buffer.append(":");
			buffer.append(forbid.getForbidRuleId());
			
			String key = svrNode + ":" + serviceCode;
			Set<String> set = configForbidTimeMapTmp.get(key);
			if (set == null) {
				set = new HashSet<>();
				set.add(buffer.toString());
				configForbidTimeMapTmp.put(key, set);
			} else {
				set.add(buffer.toString());
			}
		}
		configForbidTimeMap = configForbidTimeMapTmp;
		
		// 加载上行短信端口匹配规则
		List<MoIns> moInss = ContextUtils.getBean2(MoInsDao.class).getAllObj();
		configMoInsList = moInss != null ? moInss : new ArrayList<>();
		
		// 加载优先级配置
		Map<String, Integer> configSnodeScodePLvMapTmp = new HashMap<>();
		List<PriAlloc> priAllocs = ContextUtils.getBean2(PriAllocDao.class).getAllObj();
		for (PriAlloc priAlloc:priAllocs) {
			
			String svrNode = StringUtils.toString(priAlloc.getSvrNode());
			String serviceCode = StringUtils.toString(priAlloc.getServiceCode());
			Integer level = priAlloc.getLevel();
			
			String key = svrNode + ":" + serviceCode;
			configSnodeScodePLvMapTmp.put(key, level);
		}
		configSnodeScodePLvMap = configSnodeScodePLvMapTmp;
//		zsetOpts.removeByScore(configSnodeScodePLvZSet, 0, score -1);
		
		// 加载优先级定义表中优先级最小的项目
		PriRuleDef minLevel = ContextUtils.getBean2(PriRuleDefDao.class).getMinLevel();
		//stringOpts.set(configMinPLvString, StringUtils.toString(minLevel.getLevel()));
		configMinPLvInteger = minLevel.getLevel();
		
		// 加载优先级定义表中所有优先级
		Set<Integer> configAllPLvTmp = new HashSet<>();
		List<PriRuleDef> prds = ContextUtils.getBean2(PriRuleDefDao.class).getAllObj();
		for (PriRuleDef prd:prds) {
			Integer level = prd.getLevel();
			configAllPLvTmp.add(level);
		}
		configAllPLv = configAllPLvTmp;
		
		// 加载签名配置信息
		Map<String, String> configSnodeScodeSignMapTmp = new HashMap<>();
		List<SmSign> smSigns = ContextUtils.getBean2(SmSignDao.class).getAllObj();
		for (SmSign smSign:smSigns) {
			
			String svrNode = StringUtils.toString(smSign.getSrvNode());
			String serviceCode = StringUtils.toString(smSign.getServiceCode());
			String signContent = StringUtils.toString(smSign.getSignContent());
			
			String key = svrNode + ":" + serviceCode;
			
			configSnodeScodeSignMapTmp.put(key, signContent);
		}
		configSnodeScodeSignMap = configSnodeScodeSignMapTmp;
		
		// 业务类型路由
		Map<String, Set<String>> configScodeGtLinkIdMapTmp = new HashMap<>();
		Set<String> configAllGtLinkIdsSetTmp = new HashSet<>();
		List<SvrRouteRule> srs = ContextUtils.getBean2(SvrRouteRuleDao.class).getAllObj();
		for (SvrRouteRule sr:srs) {
			
			String serviceCode = StringUtils.toString(sr.getServiceCode());
			String gateLinkId = StringUtils.toString(sr.getGateLinkId());
			String routeLevel = StringUtils.toString(sr.getRouteLevel());
			if(StringUtils.isEmpty(routeLevel)){
				routeLevel = "999";
			}
			String value = gateLinkId + ":"+routeLevel;
			if (StringUtils.isEmpty(serviceCode)) {
				serviceCode = "*";
			}
			
			Set<String> set = configScodeGtLinkIdMapTmp.get(serviceCode);
			if (set == null) {
				set = new HashSet<>();
				set.add(value);
				configScodeGtLinkIdMapTmp.put(serviceCode, set);
			} else {
				set.add(value);
			}
			
			configAllGtLinkIdsSetTmp.add(value);
		}
		
		configScodeGtLinkIdMap = configScodeGtLinkIdMapTmp;
		configAllGtLinkIdsSet = configAllGtLinkIdsSetTmp;
		
		// 可发送省份
		Map<String, Set<String>> configProvGtLinkIdMapTmp = new HashMap<>();
		List<LinkSendPro> lsps = ContextUtils.getBean2(LinkSendProDao.class).getAllObj();
		for (LinkSendPro lsp:lsps) {
			
			String province = StringUtils.toString(lsp.getProvince());
			String gateLinkId = StringUtils.toString(lsp.getGateLinkId());
			
			Set<String> set = configProvGtLinkIdMapTmp.get(province);
			if (set == null) {
				set = new HashSet<>();
				set.add(gateLinkId);
				configProvGtLinkIdMapTmp.put(province, set);
			} else {
				set.add(gateLinkId);
			}
		}
		configProvGtLinkIdMap = configProvGtLinkIdMapTmp;
		
		// 可发送运营商
		Map<String, Set<String>> configCorpGtLinkIdMapTmp = new HashMap<>();
		List<LinkSendCorp> lscs = ContextUtils.getBean2(LinkSendCorpDao.class).getAllObj();
		for (LinkSendCorp lsc:lscs) {
			
			String mobilCorp = StringUtils.toString(lsc.getMobilCorp());
			String gateLinkId = StringUtils.toString(lsc.getGateLinkId());
			
			Set<String> set = configCorpGtLinkIdMapTmp.get(mobilCorp);
			if (set == null) {
				set = new HashSet<>();
				set.add(gateLinkId);
				configCorpGtLinkIdMapTmp.put(mobilCorp, set);
			} else {
				set.add(gateLinkId);
			}
		}
		configCorpGtLinkIdMap = configCorpGtLinkIdMapTmp;
		
		// 号段路由配置
		Map<String, String[]> configUserRouteMapTmp = new HashMap<>();
		List<UserRouteRule> usrRouteRules = ContextUtils.getBean2(UserRouteRuleDao.class).getAllObj();
		for (UserRouteRule urr:usrRouteRules) {
			
			String sectionNo = StringUtils.toString(urr.getSectionNo());
			String province = StringUtils.toString(urr.getProvince());
			String mobilCorp = StringUtils.toString(urr.getMobilCorp());
			
			configUserRouteMapTmp.put(sectionNo, new String[]{province, mobilCorp});
		}
		configUserRouteMap = configUserRouteMapTmp;
		
		// 保存运行参数Hash的key到集合RunningParamsHashSet
		setOpts2.add(RunningParamsHashSet, RunningParamsHash);
		
		
		/**
		 *  加载网关网络运行参数
		 */
		Map<String, String> gateSwitchMapTemp = new HashMap<>();
		List<GateSwitch> gateSwitchs = ContextUtils.getBean2(GateSwitchDao.class).getAllObj();
		for (GateSwitch sr:gateSwitchs) {
			String gateLinkId = StringUtils.toString(sr.getGateLinkId());
			String networkLine = StringUtils.toString(sr.getLineType());
			
			gateSwitchMapTemp.put(gateLinkId, networkLine);
			
		}		
		gateSwitchMap = gateSwitchMapTemp;
		
		/**
		 * 加载网关自动切换标志
		 */
		
		GateAutoSwitch gateAutoSwitch = ContextUtils.getBean2(GateAutoSwitchDao.class).getObject();
		if(gateAutoSwitch != null){
			gateAutoSwitchFlag = "1".equals(gateAutoSwitch.getAutoSwitch()) ? true : false;
		}
		
		/**
		 * 平台短信模板
		 */
		Map<String,PlatformSmsTemplate> smsTemplateMapTemp = new HashMap<String, PlatformSmsTemplate>();
		List<PlatformSmsTemplate> smsTemplate =  ContextUtils.getBean2(PlatformSmsTemplateDao.class).getAllObj();
		if (smsTemplate != null) {
			for (int i = 0; i < smsTemplate.size(); i++) {
				String smsTemplateType = smsTemplate.get(i).getTemplateType();

				smsTemplateMapTemp.put(smsTemplateType, smsTemplate.get(i));
			}
		}
		smsTemplateMap = smsTemplateMapTemp;
		
		//TODO 
		List<WarnRecv> warnRecvListTemp = ContextUtils.getBean2(WarnRecvDao.class).getAllObj();
		warnRecvList =  warnRecvListTemp;
		
		Map<String,ReduserList> reduserListMapTmp = new HashMap<String, ReduserList>();
		List<ReduserList> redusesrLists = ContextUtils.getBean2(ReduserListDao.class).getAllObj();
		if (redusesrLists != null) {
			for (int i = 0; i < redusesrLists.size(); i++) {
				ReduserList r = redusesrLists.get(i);
				String phone = r.getPhone();
				reduserListMapTmp.put(phone, r);
			}
		}
		reduserListMap = reduserListMapTmp;
		
		Set<String> smsCallTestPhoneMapTmp = new HashSet<String>();
		List<CallTestPhone> callTestPhoneList = ContextUtils.getBean2(CallTestPhoneDao.class).getAllObj();
		if(callTestPhoneList != null){
			for(int i = 0; i < callTestPhoneList.size(); i++){
				smsCallTestPhoneMapTmp.add(callTestPhoneList.get(i).getTestPhone());
			}
		}
		smsCallTestPhoneSet = smsCallTestPhoneMapTmp;
		
		Set<String> smsCallTestGateMapTmp = new HashSet<String>();
		List<CallTestGate> callTestGateList = ContextUtils.getBean2(CallTestGateDao.class).getAllObj();
		if(callTestPhoneList != null){
			for(int i = 0; i < callTestGateList.size(); i++){
				smsCallTestGateMapTmp.add(callTestGateList.get(i).getGateLinkId());
			}
		}
		smsCallTestGateSet = smsCallTestGateMapTmp;
		
		
		Map<Integer,Set<String>> smsCallTestMapTmp = new HashMap<Integer, Set<String>>();
		for(int i = 0 ; i < 60 ;i++){
			Set<String> set = new HashSet<String>();
			smsCallTestMapTmp.put(i, set);
		}
		List<SmsCallTest> smsCallTestList = ContextUtils.getBean2(SmsCallTestDao.class).getAllObj();
		if(smsCallTestList != null && smsCallTestList.size() > 0){
			smsCallTest = smsCallTestList.get(0);
			String sendTimeStr = smsCallTest.getSendTime();
			int sendTime = -1;
			List<Integer> times = new ArrayList<Integer>();
			if(! StringUtils.isEmpty(sendTimeStr)){
				sendTime = StringUtils.toInteger(sendTimeStr);
			}
			if(sendTime > 0){
				int val = 60/sendTime;
				for(int j = 0; j < val; j++){
					times.add(j*sendTime);
				}
				
			}
			if(times.size() > 0){
				for(int j = 0; j < times.size(); j++){
					
					for(String gateId : smsCallTestGateSet){
						for(String phone : smsCallTestPhoneSet){
							String content = gateId+","+phone+",";
							smsCallTestMapTmp.get(times.get(j)).add(content);
						}
					}
					//TODO
				}
			}
		}
		smsCallTestSentMap = smsCallTestMapTmp;
//		smsCallTestMap = smsCallTestMapTmp; 
		
		// 加载号段路由表
		Map<String, String> phoneMobileCorpTmp = new HashMap<>();
		List<UserRouteRule> userRouteRuleList = ContextUtils.getBean2(
				UserRouteRuleDao.class).getAllObj();
		for (UserRouteRule userRouteRule : userRouteRuleList) {
			String phone = userRouteRule.getSectionNo();
			String mobileCorp = userRouteRule.getMobilCorp();
			if (!StringUtils.isEmpty(phone) && !StringUtils.isEmpty(mobileCorp)) {
				phoneMobileCorpTmp.put(phone, mobileCorp);
			}
		}
		phoneMobileCorpMap = phoneMobileCorpTmp;
		
	}


}
